// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

  @property(cc.SpriteFrame)
  explodeEffect: cc.SpriteFrame = null

  onLoad () {
    this.schedule(this.onTimer, 0.016) // 计时器控制子弹飞
  }

  onTimer () {
    if (this.node.y > 300 ) {
      this.unschedule(this.onTimer) // 停止定时器
      // this.onDestroy() // 销毁节点
      this.beginExplode()
      return false
    }
    this.node.y += 10
  }

  /**
   * 爆炸
   */
  beginExplode () {
    let sp = this.node.getComponent(cc.Sprite)
    sp.spriteFrame = this.explodeEffect

    this.node.scale = 0.5

    cc.tween(this.node).to(0.5, { scale: 1, opacity: 0 })
    .call(() => {
      this.node.destroy()
    }).start()
  }

  start () {

  }

  // update (dt) {}
}
